<?php

class Mailer {
    
    public static $from = 'mailer-daemon@%s';
    
    public static function send($to, $subject, $message) {
        $from = self::getSender();
        
        $debug = Configure::read('debug');
        if ($debug > 0) {
            $email = "\n\nFrom:    {$from}\n".
                     "To:      {$to}\n".
                     "Subject: {$subject}\n".
                     "Message:\n{$message}";
            CakeLog::write('mail', $email);
        } else {
            $headers = "Content-Type: text/html; charset=utf-8\n".
                       "From: {$from}\n";
            mail($to, $subject, $message, $headers);
        }
    }
    
    public static function getSender() {
        return sprintf(self::$from, env('SERVER_NAME'));
    }
    
}